Fix: Stop incrementing hit counter while client is blocked #63
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1. Why — Problem Statement
INCRonhitKeyeven while the client was already blocked.limit, which triggered an immediate re-block.2. What Changed
blockKeyblockKeyexists → return current stats withoutINCRINCRblock-TTL ≤ 0:•
DEL blockKey•
SET hitKey 1(forced reset)block-TTL ≤ 0:•
DEL blockKey(no forced reset) → hit counter expires naturally{ totalHits, ttl, 0/1, blockTTL }; re-block loop removed3. Behavior Before vs After (Quick Example)
Config:
limit = 5,ttl = 10 s,blockDuration = 30 s200 OK200 OK429 Blocked429 Blocked429— hits keep rising429— hits do not rise200 OK4. Backward Compatibility
No breaking changes. The service interface and returned fields stay the same.
5. How to Test Quickly
limit = 2,ttl = 5 s,blockDuration = 10 s.Expected:
totalHitsstays fixed,timeToBlockExpirecounts down.Expected:
200 OK, fresh hit count starts from 1.